'''
	Andrew Oberlin, Mike Jacobs, Tom Williams
	Date: February 7, 2012
	
	Super Mario
'''
import direct.directbase.DirectStart
from panda3d.core import TextNode
from panda3d.core import Point2,Point3,Vec3,Vec4
from direct.gui.OnscreenText import OnscreenText
from direct.showbase.DirectObject import DirectObject
from direct.task.Task import Task
from math import sin, cos, pi
from random import randint, choice, random
from direct.interval.MetaInterval import Sequence
from direct.interval.FunctionInterval import Wait,Func
#from model_loader import ActorManager
from camera_controls import CameraController
from level import LevelManager
from splash_screen import TitleScreen
from overworld import Overworld
from game_stats import GameStats

class World(DirectObject):
    # PLACE ALL CONSTANTS HERE
	BLOCK_SIZE = 30
	WIN_WIDTH = 20 * BLOCK_SIZE
	WIN_HEIGHT = 15 * BLOCK_SIZE

	'''
		The constructor of the world, starts everything
	'''
	def __init__(self):
	    # setup this object to maintain the taskMgr, render node, loader
	    # makes passing this as a parent easier to classes used
	    # for example see the way ActorLoader works
		self.render = render
		self.taskMgr = taskMgr
		self.loader = loader
		self.camera = camera
		self.base = base
		
	    # setup the environment
		self.__loadModels()
		self.titleScreen = TitleScreen(self)
		self.titleScreen.show()
		self.overworld = Overworld(self)
		self.overworld.hide()
		self.__setViewpoint()
		
		self.__startMusic()

		
	
	'''
		Load all the models of the world
	'''
	def __loadModels(self):
		self.level = LevelManager(self)
		
		self.instructionsTex = self.loader.loadTexture("models/levels/menu_items/help.png")
		self.instructions = self.loader.loadModelCopy("models/plane")
		self.instructions.setTexture(self.instructionsTex)
		
		self.instructions.setHpr(Vec3(0,-90,0))
		self.instructions.setScale(self.WIN_WIDTH*0.66, self.BLOCK_SIZE, self.WIN_HEIGHT*0.5)
		self.instructions.setPos(self.WIN_WIDTH*0.33, self.WIN_HEIGHT*0.75,0)
		
		# maximize efficiency
		self.instructions.setBin("unsorted", 0)
		self.instructions.setDepthTest(False)
		self.instructions.setTransparency(1)

		self.instructions.reparentTo(render)
		self.instructions.hide()
		
	'''
	    Sets the camera up to be orthographic creating 2D effect
	'''
	def __setViewpoint(self):
		self.cameraController = CameraController(self)
	   
	   
	'''
		Starts the Mario Bros Theme Song
	'''
	def __startMusic(self):
		self.themeMusic = self.loader.loadSfx("sounds/theme_song.mp3")
		self.themeMusic.setVolume(0.6)
		self.themeMusic.setLoop(True)
		self.themeMusic.play()
		
		self.coinSound = self.loader.loadSfx("sounds/coin_sound.mp3")
		self.coinSound.setLoop(False)
		
		self.deathSound = self.loader.loadSfx("sounds/death_sound.mp3")
		self.deathSound.setLoop(False)
		
	'''
		Loads the first level and presents the player with a map
		to move around in
	'''
	def startGame(self):
		self.accept("h", self.toggleHelpInstructions)
		self.titleScreen.hide()
		self.level.hide()
		self.overworld.show()
		self.gameStats = GameStats(self)
	
	
	
		
	def toggleHelpInstructions(self):
		if (self.instructions.isHidden()):
			self.instructions.reparentTo(render)
			self.instructions.show()
		else:
			self.instructions.hide()
			
	
world = World()
run()